import Http from '../http'
import Variable from '../variable'

// 随机字符串
const getRandomString = (length: number): string => {
  const possibleChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  let randomString = ''
  for (let i = 0; i < length; i++) {
    const randomIndex = Math.floor(Math.random() * possibleChars.length)
    randomString += possibleChars.charAt(randomIndex)
  }
  return randomString
}

// 微信推送
const wxPush = (title: string, content: string, uids: string[] = [], topicIds: string[] = []) => {
  const env = Variable.getByTagNameObj('env')
  return Http({
    url: env.wxPushUrl || 'https://wxpusher.zjiecode.com/api/send/message',
    method: 'POST',
    data: {
      url: 'https://nxplus.cn',
      summary: title,
      appToken: env.wxPushToken,
      content: `<div>${content}</div><style>.note{display:none;}</style>`,
      contentType: 2,
      uids,
      topicIds,
      verifyPay: false
    }
  })
}

export { getRandomString, wxPush }
